import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:image_picker/image_picker.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/helper/AppProperties.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/helper/ImageHelper.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/helper/RouteHelper.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/helper/ViewHelper.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/view/main/mine/MineVM.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/view/main/mine/SynergyWidget.dart';

import 'WorkbenchWidget.dart';

//我的
class MineWidget extends StatefulWidget  {

  @override
  _MineState createState() => _MineState();
}

class _MineState extends State<MineWidget> with TickerProviderStateMixin{

  late TabController _tabController;
  late MineVM mineVM;
  ValueNotifier<int> cartValueNotifier= ValueNotifier(0);
  late List<Widget> list;
  final ImagePicker _picker = ImagePicker();

  @override
  void initState() {
    super.initState();
    mineVM=MineVM();
    list=[SynergyWidget(),WorkbenchWidget(mineVM)];
    _tabController=TabController(length: 2, vsync: this,initialIndex: 1);
    WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
      mineVM.getMyInfoData(isDialog:false,requestDone: (){
        cartValueNotifier.value=mineVM.mineBean?.cartQuantity??0;
        cartValueNotifier.notifyListeners();
      });
    });
  }

  @override
  void dispose() {
    super.dispose();
    _tabController.dispose();
    cartValueNotifier.dispose();
  }

  @override
  Widget build(BuildContext context) {
    var top = ScreenUtil().statusBarHeight;
    var width = MediaQuery.of(context).size.width;
    return Container(
       alignment: Alignment.topCenter,
       child: Stack(
          children: [
            Container(
              height: 158.h,
              width: double.infinity,
              alignment: Alignment.topCenter,
              color: Color(0xffff8B2D),),
            Padding(
              padding: EdgeInsets.fromLTRB(16.w,  top+12.h, 16.w, 10.h),
              child: Column(
                children: [
                  Container(
                    height: 60.h,
                    alignment: Alignment.center,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        InkWell(child: ClipOval(child:assetImage(getLoginBean().icon??"",width:32.r,height: 32.r,fit: BoxFit.fill),),onTap: (){
                          _picker.pickImage(source: ImageSource.camera);
                        },),
                        Expanded(
                          child: Container(
                            alignment: Alignment.center,
                            padding: EdgeInsets.fromLTRB(width/8, 0, width/8, 0),
                            child: TabBar(
                                controller: _tabController,
                                indicatorColor:Colors.white ,
                                indicatorWeight: 2.w,
                                // indicator:BoxDecoration(border: BorderDirectional(top:BorderSide() ),color:Colors.white,borderRadius: BorderRadius.all(Radius.circular(1.w))) ,
                                indicatorSize: TabBarIndicatorSize.label,
                                labelColor: Colors.white,
                                labelStyle: TextStyle(fontSize: 16.sp),
                                unselectedLabelColor: Color(0xffdddddd),
                                tabs: [
                                  Tab(child: Text("协同"),),
                                  Tab(child: Text("工作台"),),
                                ]),
                          ),
                        ),
                        RightTag(valueNotifier: cartValueNotifier,width: 38.sp,height: 38.sp,
                            child: SizedBox(width:16.sp,child: Image.asset(assetPath("ic_home_tab_cart_white.png"),fit: BoxFit.fitWidth,width: 16.sp,))
                        )
                      ],
                    ),
                  ),
                  Expanded(
                    child: TabBarView(
                        controller: _tabController,
                        children: list
                    ),
                  )
                ],
              ),
            ),
          ],
       ),
    );
  }
}
